﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using genlian.Models;

namespace genlian
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.dgvEList.AutoGenerateColumns = false;//禁止自动生成
            Init();
        }

       
        public void Init()
        {
            //模拟一组下拉框数据源
            List<Department> deplist = new List<Department>
            {
            new Department { DepartmentId = 10, DepartmentName = "证监会" },
         new Department { DepartmentId = 15, DepartmentName = "银保监" },
        };


            //给下拉框设置数据源
            this.cbbDepartment.DataSource= deplist;
            //还要分别绑定下面两个数据，就相当于触摸屏的ID和显示内容
            this.cbbDepartment.DisplayMember = "DepartmentName";//显示给用户的
            this.cbbDepartment.ValueMember = "DepartmentId";//这个是给后台数据用的ID号
            this.cbbDepartment.SelectedIndex = -1;//默认显示第几个



        }

        private void btnSaveDate_Click(object sender, EventArgs e)
        {
            if (this.cbbDepartment.SelectedIndex == -1)
            {

                MessageBox.Show("请选择没有选择内容");

            }
            //一下这段值得研究
            MessageBox.Show(this.cbbDepartment.SelectedText);
            MessageBox.Show(this.cbbDepartment.SelectedValue.ToString());
        }



        private void button2_Click(object sender, EventArgs e)
        {

            List<Employee> elist = new List<Employee>();

            for (int i = 0; i < 5; i++) {


                //下面这行相当于Employee初始化器
                elist.Add(
                    new Employee() 
                {


               
 EmployeeName ="员工"+i,
                    IdNo="130203199010103100"+i,
                    PhoneNumber="1300001234"+i,

    
        Post="职位"+i,
                    Department="部门"+i,
                    Province="身份"+i,

           Gender ="男",


        




    }
          
                );
        

                //Employee em=new Employee();

                //em.EmployeeName = "张三";

                //elist.Add( em );

            }


            this.dgvEList.DataSource = elist; //绑定控件

        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //创建文件打开对话框
            OpenFileDialog openFile = new OpenFileDialog();
            //以模态对话框方式打开
            DialogResult result = openFile.ShowDialog();

            if (result == DialogResult.OK)//如果用户选择了文件
            { 
            
            string path=openFile.FileName;//图片完整路径


                //判断选择文件是不是我们要的扩展名（png）
                string extName=path.Substring(path.LastIndexOf(".")+1);
                if (extName == "png" || extName == "jpg")
                {
                    this.pb_Photo.Image = Image.FromFile(path);
                    pb_Photo.SizeMode = PictureBoxSizeMode.Zoom;
                }

                else
                {

                    MessageBox.Show("格式错误");

                }

            }

        }
    }
}
